package com.example.demo2.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public Boolean login(@RequestParam("userName") String userName,  @RequestParam("password") String password , HttpSession session) {
//        判断密码的合法性
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return false;
        }

//        检查密码正确性
        if("amd".equals(userName) && "123456".equals(password)) {
//            加入到 Session 中
            session.setAttribute("userName",userName);
            return true;

        }


        return false;
    }
}
